package com.meiyu.live.ui.main;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;

import com.meiyu.live.BaseActivity;
import com.meiyu.live.R;
import com.meiyu.live.util.DisplayUtils;
import com.meiyu.live.widget.PagerSlidingTabStrip;

public class GetGiftsActivity extends BaseActivity implements View.OnClickListener {

    private String[] tabName = {"收到礼物", "收到总价"};

    private PagerSlidingTabStrip tabStrip;
    private ViewPager viewPager;
    private HomePagerAdapter pagerAdapter;
    private View btn_back;
    private static String ANCHOR_ID = "anchor_id";
    private long anchor_id;

    public static void start(Context context, long anchor_id) {
        Intent intent = new Intent(context, GetGiftsActivity.class);
        intent.putExtra(ANCHOR_ID, anchor_id);
        context.startActivity(intent);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_getgifts);
        anchor_id = getIntent().getLongExtra(ANCHOR_ID, 0);
        init();
    }

    private void init() {
        btn_back = findViewById(R.id.btn_back);
        btn_back.setOnClickListener(this);
        tabStrip = (PagerSlidingTabStrip) findViewById(R.id.tab_strip);
        tabStrip.setTextSize(DisplayUtils.dpToPixel(this, 16));
        tabStrip.setTextColorResource(R.color.black);
        viewPager = (ViewPager) findViewById(R.id.viewpager);

        pagerAdapter = new HomePagerAdapter(getSupportFragmentManager());
        viewPager.setAdapter(pagerAdapter);
        tabStrip.setViewPager(viewPager);

    }


    @Override
    public void onClick(View view) {
        if (view == btn_back) {
            finish();
        }
    }

    class HomePagerAdapter extends FragmentPagerAdapter {

        public HomePagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return tabName.length;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return tabName[position];
        }

        @Override
        public int getItemPosition(Object object) {
            return POSITION_NONE;
        }

        @Override
        public void startUpdate(ViewGroup container) {
            super.startUpdate(container);
        }

        @Override
        public Fragment getItem(int position) {
            Fragment fragment = null;
            switch (position) {
                case 0: {
                    fragment = GetGiftsFragment.start(anchor_id, GetGiftsFragment.TYPE_DETAIL);
                }
                break;
                case 1: {
                    fragment = GetGiftsFragment.start(anchor_id, GetGiftsFragment.TYPE_RANK);
                }
                break;
            }
            return fragment;
        }
    }

}
